   
   function initJqgrid(){
	   //$("#list1").tableDnD({scrollAmount:0});
	   	$( "#Grop" ).buttonset();
	   initUserTypeAutocomplete();
$("#User_list1").jqGrid({
   	url:'../userHandle/editUser.jsp',
	datatype: "xml",
   	colNames:['用户(联系人)','用户名称','用户单位','用户类型', '最后拜访时间', '地址','手机号码','拜访'],
   	colModel:[
		{name:'User_ID',index:'User_ID', width:75, },
   		{name:'User_Name',index:'User_Name', width:75,hidden:true},
		{name:'Login_Name',index:'User_Name', width:75,hidden:true},
   		{name:'User_type',index:'User_type', width:70,hidden:true,edittype:'select', formatter:'select', editoptions:{value:"1:管理员;2:业务员;3:客户;4:送货员"},},
   		{name:'Called_Time',index:'Called_Time',width:100 },
   		{name:'addr',index:'addr', width:80, align:"right"},
   		{name:'TEL',index:'TEL', width:80, align:"right"},	
		{name:'visit',index:'visit',align:"center", width:50,formatter:FmatterDel},	
   	],
	//scroll: true,
   	rowNum:10,
	scrollrows : true,
   	autowidth: true,
	height:400,
   	rowList:[10,20,30],
	prmNames:{page:'page',rows:'rows',order: 'sord', search:'_search', nd:'nd', npage:null},
	//postData:{page:'page',rows:'rows', sort: 'sidx',order: 'sordsdf'},
   	pager: jQuery('#User_pager1'),
   	sortname: 'User_ID',
    viewrecords: true,
    sortorder: "desc",
    caption:"XML Example",	
	forceFit : true,
	cellEdit: true,
	cellsubmit: 'clientArray',
	afterEditCell: function (id,name,val,iRow,iCol){
		if(name=='Called_Time') {
			jQuery("#"+iRow+"_"+name,"#User_list1").datepicker({dateFormat:"yy-mm-dd"});
		}
	},
	afterSaveCell : function(rowid,name,val,iRow,iCol) {
		
	},
	loadCompele:$("button").button(),
	loadError:function(xhr,stu,e){alert(xhr.responseText);},
	onSelectRow: function(id){    
      
   },   
	gridComplete: $( "button").button(), 
	//此事件在点击表格特定单元格时发生。rowid 为行ID；iCol 为列索引；cellcontent 为单元格中内容；e 点击事件对象
	
	onCellSelect:function(rowid,iCol,cellcontent,e){
		if(iCol==7){
			var myrow = jQuery('#User_list1').jqGrid('getRowData',rowid);
			var aa= window.confirm("是否确认今天拜访客户 "+myrow.User_ID+"？");
			if (aa) {
			
			VisitUser(myrow.User_ID);
			
			}
			}
		},
	editurl:"../userHandle/editUser.jsp"
}).navGrid('#User_pager1',{edit:false,add:false,del:false,search: false }).navButtonAdd('#User_pager1',{   
   caption:"添加",    
   buttonicon:"ui-icon-add",    
   onClickButton: function(){    
    $('#User-form').dialog('open').children('form')[0].reset();  
   },    

   position:"last"  
}).navSeparatorAdd("#User_pager1",{sepclass : "ui-separator",sepcontent: ''});	
//jQuery("#list1").jqGrid('inlineNav',"#pager1");
	   }
		   
	
		  //通过订单表的行ID获取订单ID
	   function getUser_ID_By_Row(rowid){
		   var myrow = jQuery('#User_list1').jqGrid('getRowData',rowid);
			return myrow.User_ID;
		   }  
		   
	function FmatterUserType(cellvalue, options, rowObject){
		  if(cellvalue=='1'){
			  return "管理员";
		  }else if(cellvalue=='2'){
			  return "业务员";
		  }else if(cellvalue=='3'){
			  return "客户";
		  }else if(cellvalue=='4'){
			  return "送货员";
		  }
		}
	function FmatterDel(cellvalue, options, rowObject){
			return "<button >拜访</button>";
		}
		
	function VisitUser(User_ID){
		$.ajax({
   type: "POST",
   async: false,
   dataType: "xml",
   url: "../userHandle/VisitUser.jsp",
   data: encodeURI("User_ID="+User_ID),
   success: function(xmlResponse){
    //getStart(xmlResponse);
	var statuc=$(xmlResponse).find("statuc").text();	
	if(statuc=="true"){
		$("#User_list1").trigger("reloadGrid");
		Toalert($(xmlResponse).find('msg').text());
		
		}else{
		Toalert($(xmlResponse).find('msg').text());
		}
 	},
	error: function(XMLHttpRequest, textStatus, errorThrown) {
                        alert("status:"+XMLHttpRequest.status+"readyState:"+XMLHttpRequest.readyState+"text:"+textStatus);
                    },
 });
		}
		

 function AddUserMsg(text){
	 
	 $( ".Add_User_Msg" ).text( text )
				.addClass( "ui-state-highlight" );
			setTimeout(function() {
				$( "#Add_User_Msg" ).removeClass( "ui-state-highlight", 1500 );
			}, 500 );
	 }
 function Toalert(text){
	 alert(text);
	 }
function initUserTypeAutocomplete(){
	   $("#radio1").click(
		    function(){
				findUser("find_MyUser");
			}
		);	
			$("#radio2").click(
		    function(){
				findUser("find_OtherUser");
			}
		);		
			
		$( "#Add_User_Type" ).autocomplete({
			source: "../userHandle/queryUser_Type.jsp",
			minLength: 0,
			selectedIndex:0,
			select: function( event, ui ) {
				//log( ui.item ?
				//	"Selected: " + ui.item.value + " aka " + ui.item.id :
				//	"Nothing selected, input was " + this.value );
				$(this).autocomplete({
				selectedIndex:ui.item.id,
					 });
			}
		});
		
		$( "#userid" ).autocomplete({
		//source: "../userHandle/queryUser_Type.jsp",
			minLength: 0,
			selectedIndex:0,
			 source: function (request, response) {            
			 request.page = "1";  
			 request.rows= "100"; 
			 request.User_ID=encodeURIComponent(request.term);
				$.ajax({
					url: "../userHandle/searchUser.jsp",
					data: request,
					dataType: "json",
					success: function( data, status ) {
					
							response( data );
						
					},
					error: function() {
					
							response( [] );
						
					}
				});
			 },
			select: function( event, ui ) {
				//log( ui.item ?
				//	"Selected: " + ui.item.value + " aka " + ui.item.id :
				//	"Nothing selected, input was " + this.value );
				//alert(ui.item.id)
			}
		});
		
			var dates = $( "#Start_Call_Time, #End_Call_Time" ).datepicker({
			defaultDate: "+1w",
			changeMonth: true,
			numberOfMonths: 1,
			onSelect: function( selectedDate ) {
				var option = this.id == "Start_Call_Time" ? "minDate" : "maxDate",
					instance = $( this ).data( "datepicker" ),
					date = $.datepicker.parseDate(
						instance.settings.dateFormat ||
						$.datepicker._defaults.dateFormat,
						selectedDate, instance.settings );
				dates.not( this ).datepicker( "option", option, date );
			}
		});
	}
function initfindUser(){
			$("#find").click(
		    function(){
	 findUser();
			}
		);
	}
	function findUser(find_Type){
		/*获取select 选中的 text : 
	$("#ddlRegType").find("option:selected").text(); 
	获取select选中的 value: 
	$("#ddlRegType ").val(); 
	获取select选中的索引: 
	$("#ddlRegType ").get(0).selectedIndex; 
	设置select: 
	设置select 选中的索引： 
	$("#ddlRegType ").get(0).selectedIndex=index;//index为索引值*/
	//alert("userid="+$( "#userid").val()+"  username="+$( "#username").val()+"  usertype="+$( 			"#usertype").get(0).selectedIndex);
var userid=encodeURIComponent($( "#userid").val());
var Start_Call_Time=$( "#Start_Call_Time").val();
var End_Call_Time=$( "#End_Call_Time").val();
$("#User_list1").jqGrid('setGridParam',{ url: '../userHandle/queryUser.jsp',
postData:{User_ID:userid,start_call_time:Start_Call_Time,end_call_time:End_Call_Time,find_Type:find_Type,User_Type:'3'}
}).trigger('reloadGrid'); 
		}
		
		
		function checkLength(o, n, min, max ) {
			if ( o.val().length > max || o.val().length < min ) {
				o.addClass( "ui-state-error" );
				AddUserMsg(n + " 长度必须在" +
					min + "和 " + max + "区间." );
				return false;
			} else {
				return true;
			}
		}

		function checkRegexp( o, regexp, n ) {
			if ( !( regexp.test( o.val() ) ) ) {
				o.addClass( "ui-state-error" );
				AddUserMsg( n );
				return false;
			} else {
				return true;
			}
		}
		
// JavaScript Document